/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel;

import org.rails.extjs.Option;
import org.rails.extjs.tree.DefaultSelectionModel;
import org.rails.extjs.tree.Node;
import org.rails.extjs.tree.TreeLoader;

public class TreePanel extends Panel {
	
	public TreePanel() {
		super();
	}

	public TreePanel(Node root) {
		super();
		setRoot(root);
	}

	public TreePanel(Option configOptions) {
		super(configOptions);
	}

	public TreePanel(String title,Node root) {
		super(title);
		setRoot(root);
	}

	public TreePanel(String id, String title,Node root) {
		super(id, title);
		setRoot(root);
	}
	
	public void setAnimate(Boolean animate){
		addOption("animate", animate);
	}
	
	public Boolean isAnimate(){
		return getBoolean("animate",true);
	}
	
	public void setContainerScroll(Boolean containerScroll){
		addOption("containerScroll", containerScroll);
	}
	
	public Boolean isContainerScroll(){
		return getBoolean("containerScroll",true);
	}
	
	public void setDdAppendOnly(Boolean ddAppendOnly){
		addOption("ddAppendOnly", ddAppendOnly);
	}
	
	public Boolean isDdAppendOnly(){
		return getBoolean("ddAppendOnly",true);
	}
	
	public void setDdGroup(String ddGroup){
		addOption("ddGroup", ddGroup);
	}
	
	public String getDdGroup(){
		return getString("ddGroup","");
	}
	
	public void setDdScroll(Boolean ddScroll){
		addOption("ddScroll", ddScroll);
	}
	
	public Boolean isDdScroll(){
		return getBoolean("ddScroll",true);
	}
	
	public void setEnableDD(Boolean enableDD){
		addOption("enableDD", enableDD);
	}
	
	public Boolean isEnableDD(){
		return getBoolean("enableDD",true);
	}
	
	public void setEnableDrag(Boolean enableDrag){
		addOption("enableDrag", enableDrag);
	}
	
	public Boolean isEnableDrag(){
		return getBoolean("enableDrag",true);
	}
	
	public void setEnableDrop(Boolean enableDrop){
		addOption("enableDrop", enableDrop);
	}
	
	public Boolean isEnableDrop(){
		return getBoolean("enableDrop",true);
	}
	
	public void setHlColor(String hlColor){
		addOption("hlColor", hlColor);
	}
	
	public String getHlColor(){
		return getString("hlColor","C3DAF9");
	}
	
	public void setHlDrop(Boolean hlDrop){
		addOption("hlDrop", hlDrop);
	}
	
	public Boolean isHlDrop(){
		return getBoolean("hlDrop",true);
	}
	
	public void setLines(Boolean lines){
		addOption("lines", lines);
	}
	
	public Boolean isLines(){
		return getBoolean("lines",true);
	}
	
	public void setLoader(TreeLoader loader){
		addOption("loader", loader);
	}
	
	public TreeLoader getLoader(){
		return (TreeLoader)getOption("loader");
	}
	
	public void setPathSeparator(String pathSeparator){
		addOption("pathSeparator", pathSeparator);
	}
	
	public String getPathSeparator(){
		return getString("pathSeparator","/");
	}
	
	public void setRequestMethod(String requestMethod){
		addOption("requestMethod", requestMethod);
	}
	
	public String getRequestMethod(){
		return getString("requestMethod","GET");
	}
	
	public void setRoot(Node root){
		addOption("root",root);
	}
	
	public Node getRoot(){
		return (Node)getOption("root");
	}
	
	public void setRootVisible(Boolean rootVisible){
		addOption("rootVisible", rootVisible);
	}
	
	public Boolean isRootVisible(){
		return getBoolean("rootVisible",true);
	}
	
	public void setSelModel(DefaultSelectionModel selModel){
		addOption("selModel", selModel);
	}
	
	public DefaultSelectionModel getSelModel(){
		return (DefaultSelectionModel)getOption("selModel");
	}
	
	public void setSingleExpand(Boolean singleExpand){
		addOption("singleExpand", singleExpand);
	}
	
	public Boolean isSingleExpand(){
		return getBoolean("singleExpand", true);
	}
	
	public void setTrackMouseOver(Boolean trackMouseOver){
		addOption("trackMouseOver", trackMouseOver);
	}
	
	public Boolean isTrackMouseOver(){
		return getBoolean("trackMouseOver",false);
	}
	
	public void setUseArrows(Boolean useArrows){
		addOption("useArrows", useArrows);
	}
	
	public Boolean isUseArrows(){
		return getBoolean("useArrows",false);
	}

	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.tree.TreePanel(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}
	
}
